﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security;
using System.Runtime.InteropServices;

namespace Revis.VClinicNet.Util.Extensions
{
    public static class SecureStringExtension
    {
        public static string ToUnsecureString(this SecureString secureString)
        {
            if (secureString == null) {
                throw new ArgumentNullException("secureString");
            }
            IntPtr unmenagedString = IntPtr.Zero;
            try {
                unmenagedString = Marshal.SecureStringToGlobalAllocUnicode(secureString);
                return Marshal.PtrToStringUni(unmenagedString);
            } finally {
                Marshal.ZeroFreeGlobalAllocUnicode(unmenagedString);
            }
        }
    }
}
